package thread.modoel;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Package javaSE.thread.modoel @Author shimmer @Date 2020/5/14 18:27 @TODO 测试线程池
 */
public class 线程池 {
    public static void main(String[] args) {
        // 1.创建服务，创建线程池
        // newFixedThreadPool 参数为：线程池大小
        ExecutorService service = Executors.newFixedThreadPool(10);

        // 2.执行
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());

        // 3.关闭
        service.shutdown();
    }

    static class MyThread extends Thread {
        @Override
        public void run() {
            System.out.println(this.getName());
        }
    }
}
